package com.winchain.chainbill.receivables.biz.mod.cmd;

import com.shell.bee.acct.transaction.po.AcctTxRec;
import com.shell.framework.command.CallbackContext;
import com.shell.framework.command.CommandContext;
import com.shell.framework.command.ICallback;
import com.shell.framework.command.ICommand;
import com.winchain.chainbill.receivables.base.po.ArModification;
import com.winchain.chainbill.receivables.base.po.ArRecord;
import com.winchain.chainbill.receivables.base.service.ArModService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ReceivablesModCmd implements ICommand<ArRecord>, ICallback<ArRecord, AcctTxRec> {
	@Autowired
	private ArModService arModService;

	public boolean execute(CommandContext<ArRecord> context) throws Exception {
		ArRecord record = (ArRecord) context.getSource();
		ArModification mod = (ArModification) context.getValue("ArModification");
		mod.setOptSeq(record.getOptSeq());
		if (record.getArState().equals(mod.getArStateOrig())) {
			mod.setModState("0");
		} else {
			mod.setModState("1");
		}
		this.arModService.saveOrUpdate(mod);
		return false;
	}

	public boolean callback(CallbackContext<ArRecord, AcctTxRec> context) throws Exception {
		execute(context);
		return false;
	}
}
